<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    JVM探究 |  Yolin
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.png" />
  
  
<link rel="stylesheet" href="/css/style.css">

  
<script src="/js/pace.min.js"></script>


  

  

<link rel="alternate" href="/atom.xml" title="Yolin" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-JVM探究" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  JVM探究
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2021/01/10/JVM%E6%8E%A2%E7%A9%B6/" class="article-date">
  <time datetime="2021-01-10T08:45:02.000Z" itemprop="datePublished">2021-01-10</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/Java/">Java</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.2k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">8分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="JVM内存结构"><a href="#JVM内存结构" class="headerlink" title="JVM内存结构"></a>JVM内存结构</h2><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2021-01-09_17-35-32.jpg" alt=""></p>
<h2 id="JDK1-8为何用元空间取代永久代？"><a href="#JDK1-8为何用元空间取代永久代？" class="headerlink" title="JDK1.8为何用元空间取代永久代？"></a>JDK1.8为何用元空间取代永久代？</h2><p>类及方法的信息等比较难确定其大小，因此对于永久代大小指定比较困难，太小容易出现永久代溢出，太大容易出现老年代溢出。</p>
<p>而且永久代为GC带来不必要的复杂度，且回收效率低。</p>
<h2 id="字符串常量、类文件常量池所在区域"><a href="#字符串常量、类文件常量池所在区域" class="headerlink" title="字符串常量、类文件常量池所在区域"></a>字符串常量、类文件常量池所在区域</h2><p>字符串常量在堆中分配，类文件常量池位于方法区，即元空间。</p>
<a id="more"></a>
<h2 id="类加载过程"><a href="#类加载过程" class="headerlink" title="类加载过程"></a>类加载过程</h2><ul>
<li><strong>加载</strong>：堆中生成class字节码对象</li>
<li><strong>验证</strong>：校验字节码文件正确性，确保class文件的字节流信息符合JVM要求</li>
<li><strong>准备</strong>：为类的静态变量分配内存并将其初始化为默认值</li>
<li><strong>解析</strong>：JVM将常量池内的符号引用替换成直接引用</li>
<li><strong>初始化</strong>：执行类构造器初始化的过程</li>
</ul>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2021-01-11_15-49-57.jpg" alt=""></p>
<h3 id="什么时候发生类的初始化"><a href="#什么时候发生类的初始化" class="headerlink" title="什么时候发生类的初始化"></a>什么时候发生类的初始化</h3><ul>
<li>初始化main方法时</li>
<li>new一个类的对象</li>
<li>调用类的静态成员和方法时</li>
<li>使用java.lang.reflect包的方法对类进行反射调用</li>
</ul>
<h2 id="对象的创建过程"><a href="#对象的创建过程" class="headerlink" title="对象的创建过程"></a>对象的创建过程</h2><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2021-01-09_18-52-12.jpg" alt=""></p>
<h2 id="常见类加载器"><a href="#常见类加载器" class="headerlink" title="常见类加载器"></a>常见类加载器</h2><pre><code>-   Bootstrap ClassLoader(启动类加载器，c语言写的，负责加载jre/bin下的核心类库，如rt.jar)
    |
-   Extension ClassLoader(扩展类加载器)
    |
-   Application ClassLoader(应用程序类加载器,加载自己写的class)</code></pre><p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2021-01-19_22-16-28.jpg" alt=""></p>
<h2 id="什么是双亲委派机制"><a href="#什么是双亲委派机制" class="headerlink" title="什么是双亲委派机制"></a>什么是双亲委派机制</h2><p>当一个类收到类加载请求时，不会自己先去加载这个类，而是将其委派给父类，由父类去加载，如果父类不能加载，这时会反馈给子类，再由子类去完成。</p>
<p><strong>也就是说如果一个类可以被委派最基础的ClassLoader加载，就不能让高层的ClassLoader加载。</strong></p>
<p>这样可以保证我们不能修改java.已有的类</p>
<h2 id="破坏双亲委派机制的实例"><a href="#破坏双亲委派机制的实例" class="headerlink" title="破坏双亲委派机制的实例"></a>破坏双亲委派机制的实例</h2><p>打破双亲委派机制典型的两个方法：</p>
<ul>
<li>自定义类加载器，重写loadClass方法</li>
<li>使用线程上下文类加载器</li>
</ul>
<p>首先看一下JDBC连接数据库加载驱动的代码</p>
<p><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2021-01-21_15-22-52.jpg" alt=""></p>
<p>再看看DriverManager 的初始化方法loadInitialDrivers</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">loadInitialDrivers</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    String drivers;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="comment">//读取系统属性</span></span><br><span class="line">        drivers = AccessController.doPrivileged(<span class="keyword">new</span> PrivilegedAction&lt;String&gt;() &#123;</span><br><span class="line">            <span class="function"><span class="keyword">public</span> String <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line">                <span class="keyword">return</span> System.getProperty(<span class="string">"jdbc.drivers"</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception ex) &#123;</span><br><span class="line">        drivers = <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    </span><br><span class="line">    <span class="comment">//通过SPI加载驱动类</span></span><br><span class="line">    AccessController.doPrivileged(<span class="keyword">new</span> PrivilegedAction&lt;Void&gt;() &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> Void <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">            ServiceLoader&lt;Driver&gt; loadedDrivers = ServiceLoader.load(Driver<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">            Iterator&lt;Driver&gt; driversIterator = loadedDrivers.iterator();</span><br><span class="line"></span><br><span class="line">            <span class="keyword">try</span>&#123;</span><br><span class="line">                <span class="keyword">while</span>(driversIterator.hasNext()) &#123;</span><br><span class="line">                    driversIterator.next();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">catch</span>(Throwable t) &#123;</span><br><span class="line">            <span class="comment">// Do nothing</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    println(<span class="string">"DriverManager.initialize: jdbc.drivers = "</span> + drivers);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (drivers == <span class="keyword">null</span> || drivers.equals(<span class="string">""</span>)) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    String[] driversList = drivers.split(<span class="string">":"</span>);</span><br><span class="line">    println(<span class="string">"number of Drivers:"</span> + driversList.length);</span><br><span class="line">    <span class="keyword">for</span> (String aDriver : driversList) &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            println(<span class="string">"DriverManager.Initialize: loading "</span> + aDriver);</span><br><span class="line">            <span class="comment">//通过类加载器加载</span></span><br><span class="line">            Class.forName(aDriver, <span class="keyword">true</span>,</span><br><span class="line">                    ClassLoader.getSystemClassLoader());</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception ex) &#123;</span><br><span class="line">            println(<span class="string">"DriverManager.Initialize: load failed: "</span> + ex);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>可以看到先是获取jdbc.drivers属性，得到了的路径，然后通过应用程序类加载器加载<br><img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/Snipaste_2021-01-21_16-59-38.jpg" alt=""></p>
<h2 id="堆和栈的区别"><a href="#堆和栈的区别" class="headerlink" title="堆和栈的区别"></a>堆和栈的区别</h2><p>存放内容不同：</p>
<blockquote>
<p>  堆存放对象的实例和数组，因此更关心数据存放</p>
<p>  栈存放局部变量、操作数栈和返回结果，所以更关心程序的执行</p>
</blockquote>
<p>内存区别：</p>
<blockquote>
<p>  堆不连续，所以分配内存在 <strong>运行期</strong> 确认，大小不固定</p>
<p>  栈是连续的，分配内存在 <strong>编译器</strong> 确认，大小固定</p>
</blockquote>
<h2 id="什么是OOM"><a href="#什么是OOM" class="headerlink" title="什么是OOM"></a>什么是OOM</h2><p>（Out Of Memory）,指内存不足，内存溢出了</p>
<p>当JVM没有足够内存来为对象分配并且垃圾回收器也没有空间回收时会出现该情况。</p>
<p>常见的OOM有：</p>
<ul>
<li><strong>堆内存溢出</strong>（最常见）：<strong>一般由于内存泄漏</strong>（<em>申请使用完内存没有释放导致虚拟机不能再次使用该内存<em>）*</em>或堆大小设置不当引起.*<em>(</em>解决的话用JVM配置参数-Xmx设置堆大小</em>)</li>
<li><strong>栈内存溢出</strong>：<strong>一般由死循环或深度递归造成</strong>。</li>
</ul>
<blockquote>
<h2 id="四大垃圾回收算法"><a href="#四大垃圾回收算法" class="headerlink" title="四大垃圾回收算法"></a>四大垃圾回收算法</h2></blockquote>
<h2 id="标记清除算法（Mark-Sweep）"><a href="#标记清除算法（Mark-Sweep）" class="headerlink" title="标记清除算法（Mark-Sweep）"></a>标记清除算法（Mark-Sweep）</h2><p><strong>（标记无用对象，然后进行清除回收）</strong>，它将垃圾收集分为两个阶段：标记阶段、清除阶段。其优点是实现简单，缺点是效率低，且产生大量不连续的内存碎片</p>
<h2 id="复制算法-Copy"><a href="#复制算法-Copy" class="headerlink" title="复制算法(Copy)"></a>复制算法(Copy)</h2><p><strong>(把内存空间分为两个相等的区域，每次只使用一个，垃圾回收时，遍历当前区域，把存活的对象复制到另一个区域，最后将可回收对象进行回收)</strong></p>
<ul>
<li>优点是运行高效，不考虑内存碎片。</li>
<li>缺点是可用内存大小为原来的一半，对象存活率高时要频繁复制操作。</li>
</ul>
<p>扩充：Java堆中被分为了新生代和老年代，这样的划分是方便GC。Java堆中的新生代就使用了GC复制算法。在新生代中又分为了三个区域：Eden、To Survivor、 From Survivor，默认比例是8:1:1</p>
<h2 id="标记整理算法（Mark-Compact）"><a href="#标记整理算法（Mark-Compact）" class="headerlink" title="标记整理算法（Mark-Compact）"></a>标记整理算法（Mark-Compact）</h2><p><strong>(标记可回收对象，再将存活的对象移动到内存另一端，清空占用内存边界以外的内存)</strong></p>
<ul>
<li>优点：不考虑内存碎片</li>
<li>缺点：对象移动的代价比较大，会降低效率。</li>
</ul>
<h2 id="分代收集算法"><a href="#分代收集算法" class="headerlink" title="分代收集算法"></a>分代收集算法</h2><p>分为新生代和老年代，新生代默认占总空间的1/3，老年代默认占2/3.</p>
<p>新生代使用的复制算法，有三个分区：Eden、To Survivor、 From Survivor，默认比例是8:1:1。它的执行流程是：</p>
<ol>
<li>把Eden + From Survivor存活的对象放入To Survivor区；</li>
<li>清空Eden和From Survivor分区；</li>
<li>From Survivor和To Survivor分区交换，From Survivor变成To Survivor,反之</li>
</ol>
<p>每移动一次，对象年龄加1，当年龄大于阈值15时，会移动到老年代。</p>
<p>老年代当空间占用达到某个值之后就会触发全局垃圾回收，一般用标记整理算法。</p>
<h2 id="JVM如何判断哪些对象需要删除？"><a href="#JVM如何判断哪些对象需要删除？" class="headerlink" title="JVM如何判断哪些对象需要删除？"></a>JVM如何判断哪些对象需要删除？</h2><p>引用计数器法：通过一个对象的引用计数器的值来判断该对象是否被引用了。但是存在循环引用的情况，两个对象之间彼此引用，但没有被其他对象引用，缺不能回收，所以一般不用。</p>
<p>可达性分析算法：根据GC Roots进行查找标记，依次向下搜索，搜素走过的路径称为引用链（Reference Chain）,当一个对象不能和任何一个GC Root产生关系时，就判定为垃圾。</p>
<h2 id="可作为GC-Roots的对象"><a href="#可作为GC-Roots的对象" class="headerlink" title="可作为GC Roots的对象"></a>可作为GC Roots的对象</h2><ul>
<li>虚拟机栈中引用的对象</li>
<li>方法区中常量引用的对象</li>
<li>方法区中类静态属性引用的对象</li>
<li>Native方法引用的对象</li>
</ul>
<h2 id="强引用、软引用、弱引用、虚引用"><a href="#强引用、软引用、弱引用、虚引用" class="headerlink" title="强引用、软引用、弱引用、虚引用"></a>强引用、软引用、弱引用、虚引用</h2><p>（被引用的对象一定能存活吗？）</p>
<ul>
<li>强引用：普通的对象引用关系，如String s=new String(“jin”);只有设置obj==null，JVM才会回收</li>
<li>软引用：一般用于维护可有可无的对象，只有在内存不足时才会被回收。</li>
<li>弱引用：在JVM进行回收时，无论内存是否充足，都会被回收</li>
<li>虚引用：用的不多，主要是用来跟踪对象被GC的活动。</li>
</ul>
<h2 id="CMS垃圾回收器"><a href="#CMS垃圾回收器" class="headerlink" title="CMS垃圾回收器"></a>CMS垃圾回收器</h2><p>CMS（Concurrent Mark-Sweep ）,Concurrent是指多线程，Mark-Sweep说明它是使用标记清除算法实现，所以在gc的时候会产生大量的内存碎片。</p>
<p>收集过程：</p>
<ul>
<li><strong>初始标记</strong>：只是标记GC Roots能直接关联的对象，速度很快，会暂停工作线程。</li>
<li><strong>并发标记</strong>：标记GC Roots间接相关对象，和用户线程一起执行，不需要暂停工作线程</li>
<li><strong>重新标记</strong>：重新标记新产生的垃圾，因用户线程运行时会导致某些标记产生变动。</li>
<li><strong>并发清除</strong>：并发清除垃圾。</li>
</ul>
<h2 id="G1垃圾收集器"><a href="#G1垃圾收集器" class="headerlink" title="G1垃圾收集器"></a>G1垃圾收集器</h2><p>它是别称为垃圾回收器里最前沿的成果，它最突出的改进是：</p>
<ol>
<li>基于标记-整理算法，不产生内存碎片</li>
<li>在不牺牲吞吐量前提下，实现低停顿垃圾回收</li>
</ol>
<p>是把堆内存分为大小固定的独立区域，并跟踪这些区域的垃圾收集进度，优先回收垃圾最多的区域。</p>
<h2 id="JVM调优中查看JVM参数默认值"><a href="#JVM调优中查看JVM参数默认值" class="headerlink" title="JVM调优中查看JVM参数默认值"></a>JVM调优中查看JVM参数默认值</h2><p>jsp -v 查看jvm进程显示指定的参数</p>
<p>jinfo 可实时查看调整虚拟机各项参数</p>
<h2 id="常见的JVM配置参数有哪些？"><a href="#常见的JVM配置参数有哪些？" class="headerlink" title="常见的JVM配置参数有哪些？"></a>常见的JVM配置参数有哪些？</h2><p>-Xmx:设置堆的最大内存，默认为物理内存的1/4</p>
<p>-Xms:设置堆初始化内存大小，默认为物理内存的1/64</p>
<p>-Xmn:设置新生代内存大小</p>
<p>-Xss:设置线程栈大小</p>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JVM/" rel="tag">JVM</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2021/01/16/HashMap%E6%8E%A2%E7%A9%B6-1/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            HashMap探究
          
        </div>
      </a>
    
    
      <a href="/2020/12/23/%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%86%85%E5%AE%B9%E6%A2%B3%E7%90%86/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">多线程内容梳理</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        notify: false,
        verify: '',
        app_id: '',
        app_key: '',
        path: window.location.pathname,
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020-2021
        张金
      </li>
      <li>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
        <img src="https://yolin121.oss-cn-beijing.aliyuncs.com/blogimg/beian.png">
        <a href="https://beian.miit.gov.cn"  style="color:#f72b07" target="_blank">陕ICP备20002449号</a>
      </li>

    </ul>
  </div>
</footer>
    <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
      <aside class="sidebar">
        <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Yolin"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/playlist">歌单</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/video">视频</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友情链接</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
      </aside>
      <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
      
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>




<script>
  try {
    var typed = new Typed("#subtitle", {
    strings: ['肠断月明红豆蔻,','月似当时,','人似当时否？'],
    startDelay: 1500,
    typeSpeed: 200,
    loop: true,
    backSpeed: 40,
    showCursor: true
    });
  } catch (err) {
  }
  
</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer:'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>


<script>
  var ayerConfig = {
    mathjax: true
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>



<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>


<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
  </div>
</body>

</html>